<template>
  <div class="container">
    <Header><span>找回密码</span></Header>
    <section>
      <div class="update-pwd">
        <input
          type="text"
          placeholder="请输入新密码"
          pattern="[0-9*]"
          v-model.trim="userPwd"
        />
      </div>

      <div class="update" @click="updateBtn">确 认</div>
    </section>
    <Tabbar></Tabbar>
  </div>
</template>
    
    <script>
import Tabbar from "@/components/common/Tabbar.vue";
import Header from "@/components/common/Header.vue";
import { Toast } from "mint-ui";
//引入封装后的axiox
import http from "@/common/api/request";
export default {
  components: { Tabbar, Header },
  name: "RecoveryBtn",
  data() {
    return {
      userPwd: "",

      rules: {
        //密码验证
        userPwd: {
          rule: /^\w{6,12}$/,
          msg: "密码不能为空,且为6~12位",
        },
      },
    };
  },
  methods: {
    updateBtn() {
      if (!this.validata("userPwd")) return;
      //确认修改密码
      http
        .$axios({
          url: "/api/recovery",
          method: "Post",
          data: {
            phone: this.$route.params.phone,
            pwd: this.userPwd,
          },
        })
        .then((res) => {
          if (res.success) {
            Toast("修改成功");
            this.$router.push({
              path: "/UserLogin",
            });
          }
        });
    },
    //验证信息提示
    validata(key) {
      let bool = true;
      if (!this.rules[key].rule.test(this[key])) {
        Toast(this.rules[key].msg);
        bool = false;
      }
      return bool;
    },
  },
};
</script>
    
    <style scoped lang="scss">
section {
  display: flex;
  flex-direction: column;
  align-items: center;
  background-color: #f5f5f5;
  font-size: 0.32rem;
  div {
    margin: 0.32rem 0;
    width: 8.933333rem;
    height: 1rem;
  }
  input {
    box-sizing: border-box;
    padding: 0 0.3rem;
    line-height: 1rem;
    background-color: #fff;
    border-radius: 8px;
  }
  .update-pwd {
    margin-top: 0.8rem;
    input {
      width: 8.933333rem;
    }
  }

  .update {
    line-height: 1rem;
    background-color: #b0352f;
    border-radius: 6px;
    text-align: center;
    color: #fff;
    margin-bottom: 0.8rem;
    font-size: 0.48rem;
  }
}
</style>